<?php

/**
 * This is the model class for table "texts".
 *
 * The followings are the available columns in table 'texts':
 * @property string $id
 * @property integer $user_id
 * @property string $txt
 * @property string $fti_txt
 * @property string $last_update
 */
class Texts extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return texts the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'texts';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('user_id, txt', 'required'),
			array('user_id', 'numerical', 'integerOnly'=>true),
			array('fti_txt, last_update', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('user_id, txt, last_update', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'user' => array(self::BELONGS_TO, 'Users', 'user_id'),
			//'diary_notes' => array(self::HAS_MANY, 'DiaryNotes', 'txt_id'),
			//'diaries' => array(self::HAS_MANY, 'Diary', 'txt_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'txt_id' => 'Id',
			'user_id' => 'User',
			'txt' => 'Текст',
			'fti_txt' => 'Fti Txt',
			'last_update' => 'Last Update',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id,true);

		$criteria->compare('user_id',$this->user_id);

		$criteria->compare('txt',$this->txt,true);

		$criteria->compare('fti_txt',$this->fti_txt,true);

		$criteria->compare('last_update',$this->last_update,true);

		return new CActiveDataProvider('Texts', array(
			'criteria'=>$criteria,
		));
	}
}